package com.msb.search.mq;

import com.msb.common.constart.RabbitMQConstants;
import com.msb.common.model.StandardReport;
import com.msb.search.service.SearchService;
import com.msb.search.utils.SearchUtils;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;

/**
 * @Author: lmf
 * @Create: 2025/3/24 8:24
 * @module
 */
@Component
@Slf4j
public class SmsUpdateLogListener {

    @Resource
    private SearchService searchService;


    @RabbitListener(queues = RabbitMQConstants.SMS_GATEWAY_DEAD_QUEUE)
    public void smsUpdateConsume(StandardReport report, Channel channel, Message message) throws IOException {
        log.info("收到短信网关死信队列消息 report={}", report);
        SearchUtils.setReport(report);

        HashMap<String, Object> map = new HashMap<>();
        map.put("reportState", report.getReportState());
        searchService.update(SearchUtils.getYearIndex(), report.getSequenceId().toString(), map);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        log.info("修改短信网关索引成功 report={}", report);

    }

}
